<template>
	<view class="content">
		<uni-list>
			<uni-list-item @tap="go(val)" :title="val.title" v-for="val of list" :key="val.id"></uni-list-item>
		</uni-list>
		<uni-load-more :status="isMore"></uni-load-more>
	</view>
</template>

<script>
	import CHONG from '../../static/js/function.js';
	import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
	import uniList from '@/components/uni-list/uni-list.vue'
	import uniListItem from '@/components/uni-list-item/uni-list-item.vue'
	import {
		mapState,
		mapMutations
	} from 'vuex';
	export default {
		data() {
			return {
				list: [],
				isMore: 'more',
				isXiaLa: true,
				isLa: true,
				reqData: {
					pageNumber: 0,
					pageSize: 20
				}
			}
		},
		onLoad() {
			this.getList();
		},
		onReachBottom() {
			if (this.isLa) {
				this.getList();
			}
		},
		onPullDownRefresh() {
			if (this.isXiaLa) {
				this.isXiaLa = false;
				this.isLa = true;
				this.isMore = 'more';
				this.reqData = {
					pageNumber: 0,
					pageSize: 20
				};
				this.list = [];
				this.getList();
			} else {
				uni.stopPullDownRefresh();
			}
		},
		methods: {
			getList() {
				this.isMore = 'loading';
				uni.request({
					url: this.URL + "noticePageList",
					data: this.reqData,
					success: (res) => {
						console.log("通知列表");
						console.log(res.data);
						uni.stopPullDownRefresh();
						setTimeout(() => {
							this.isXiaLa = true;
						}, 5000);
						this.list = [...this.list, ...res.data.data];
						if (res.data.total <= this.list.length + this.reqData.pageNumber) {
							this.isMore = 'noMore'
							this.isLa = false;
						};
						this.reqData.pageNumber += this.reqData.pageSize;
					}
				})
			},
			go(req) {
				uni.setStorage({
					key: "xiangqing",
					data: req,
					success: (res) => {
						console.log('成功');
						uni.navigateTo({
							url: "./noticeDetails"
						})
					},
				})
			}
		},
		computed: mapState(['URL']),
		components: {
			uniList,
			uniListItem,
			uniLoadMore
		}
	}
</script>

<style>
</style>
